package org.zw.android.framework.http;

import android.content.Context;
import android.os.Message;

public abstract class HttpUIHandlerDownload extends HttpUIHandler {
	
	public static final int MSG_DOWNLOAD_FILE_CALLBACK		= MSG_PARSER_FILTER_FAILED + 1 ;
	public static final int MSG_DOWNLOAD_PROCESSING			= MSG_DOWNLOAD_FILE_CALLBACK + 1 ;
	
	public HttpUIHandlerDownload() {
		super(null);
	}

	public HttpUIHandlerDownload(Context context) {
		super(context);
	}

	@Override
	protected final void notifyHttpUI(Message msg) {
		
		if(msg.what == MSG_DOWNLOAD_FILE_CALLBACK){
			notifyDownloadFinish(msg);
		} if(msg.what == MSG_DOWNLOAD_PROCESSING){
			notifyDownloadProgress(msg.obj,msg.arg1,msg.arg2);
		}
	}

	@Override
	protected void notifyNormalFilterFailed(Message msg) {
		
	}

	@Override
	protected void notifyParserFilterFailed(Message msg) {
		
	}

	@Override
	protected void notifyError(Message msg) {
		
	}

	@Override
	protected void notifyCancel(Message msg) {
		
	}
	
	// failed message
	protected abstract void notifyDownloadFinish(Message msg);

	// failed message
	protected abstract void notifyDownloadProgress(Object obj,int total, int readed);
	
	/**
	 * Download callback Filter failed
	 */
	public void sendDownloadFinish(Object obj){
		obtainMessage(MSG_DOWNLOAD_FILE_CALLBACK,obj).sendToTarget();
	}
	
	/**
	 * Download Progress
	 * 
	 * @param total
	 * @param readed
	 */
	public void sendDownloadProgress(Object obj ,long total, int readed){
		obtainMessage(MSG_DOWNLOAD_PROCESSING, (int)total, readed,obj).sendToTarget() ;
	}

}
